//
//  TabBarViewController.m
//  Sports-Go
//
//  Created by rimi on 16/9/29.
//  Copyright © 2016年 YRL. All rights reserved.
//

#import "TabBarViewController.h"

@interface TabBarViewController ()<UITabBarDelegate>
@property(nonatomic,assign)NSInteger indexFlag;
@property (nonatomic,strong)UITabBar *tabbar;
@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabbar.delegate = self;
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {

    NSInteger index = [self.tabBar.items indexOfObject:item];

    if (self.indexFlag != index) {
        [self animationWithIndex:index];
    }

}
// 动画
- (void)animationWithIndex:(NSInteger) index {
    NSMutableArray * tabbarbuttonArray = [NSMutableArray array];
    for (UIView *tabBarButton in self.tabBar.subviews) {
        if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [tabbarbuttonArray addObject:tabBarButton];
        }
    }
    CABasicAnimation*pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    pulse.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pulse.duration = 0.1;
    pulse.repeatCount= 1;
    pulse.autoreverses= YES;
    pulse.fromValue= [NSNumber numberWithFloat:0.7];
    pulse.toValue= [NSNumber numberWithFloat:2.3];
    [[tabbarbuttonArray[index] layer]
     addAnimation:pulse forKey:nil];

    self.indexFlag = index;

}


@end
